package com.moxiao.yfjh.module.blind.controller.admin.recommendRecord;

import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordExcelVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordUpdateReqVO;
import com.moxiao.yfjh.module.blind.convert.recommendRecord.RecommendRecordConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.recommendRecord.RecommendRecordDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;

import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;

import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.*;
import com.moxiao.yfjh.module.blind.service.recommendRecord.RecommendRecordService;

@Tag(name = "管理后台 - 相亲超级推荐记录")
@RestController
@RequestMapping("/blind/recommend-record")
@Validated
public class RecommendRecordController {

    @Resource
    private RecommendRecordService recommendRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲超级推荐记录")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:create')")
    public CommonResult<Long> createRecommendRecord(@Valid @RequestBody RecommendRecordCreateReqVO createReqVO) {
        return success(recommendRecordService.createRecommendRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲超级推荐记录")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:update')")
    public CommonResult<Boolean> updateRecommendRecord(@Valid @RequestBody RecommendRecordUpdateReqVO updateReqVO) {
        recommendRecordService.updateRecommendRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲超级推荐记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:delete')")
    public CommonResult<Boolean> deleteRecommendRecord(@RequestParam("id") Long id) {
        recommendRecordService.deleteRecommendRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲超级推荐记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:query')")
    public CommonResult<RecommendRecordRespVO> getRecommendRecord(@RequestParam("id") Long id) {
        RecommendRecordDO recommendRecord = recommendRecordService.getRecommendRecord(id);
        return success(RecommendRecordConvert.INSTANCE.convert(recommendRecord));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲超级推荐记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:query')")
    public CommonResult<List<RecommendRecordRespVO>> getRecommendRecordList(@RequestParam("ids") Collection<Long> ids) {
        List<RecommendRecordDO> list = recommendRecordService.getRecommendRecordList(ids);
        return success(RecommendRecordConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲超级推荐记录分页")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:query')")
    public CommonResult<PageResult<RecommendRecordRespVO>> getRecommendRecordPage(@Valid RecommendRecordPageReqVO pageVO) {
        PageResult<RecommendRecordDO> pageResult = recommendRecordService.getRecommendRecordPage(pageVO);
        return success(RecommendRecordConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲超级推荐记录 Excel")
    @PreAuthorize("@ss.hasPermission('blind:recommend-record:export')")
    @OperateLog(type = EXPORT)
    public void exportRecommendRecordExcel(@Valid RecommendRecordExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<RecommendRecordDO> list = recommendRecordService.getRecommendRecordList(exportReqVO);
        // 导出 Excel
        List<RecommendRecordExcelVO> datas = RecommendRecordConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲超级推荐记录.xls", "数据", RecommendRecordExcelVO.class, datas);
    }

}
